package com_djm_2025_05_11;

/**
 * @author dengjiangming
 * @version 1.1.0
 * @date 2025-05-14
 */
public class Demo6 {
    //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。


    public static void main(String[] args) {
        int sign = 1;
        double sum = 0.0;
        for (double i = 1; i <= 100.0; i++) {
            double num = 1 / i;
            sum += num * sign;
            sign = -sign;
        }

        System.out.println(sum);
    }
}
